<template>
  <div>
    <el-table :data="userList" border stripe style="width: 100%">
      <el-table-column type="index" label="序号" width="80"></el-table-column>
      <el-table-column prop="id" label="学号"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="age" label="年龄"></el-table-column>
      <el-table-column prop="position" label="职位"></el-table-column>
      <el-table-column prop="addtime" label="更新时间"></el-table-column>
    </el-table>
  </div>
</template>

<script>
// 1.引入 element-ui 组件
import { Badge } from 'element-ui'

export default {
  name: 'UserList',
  components: {
    // 2.局部注册
    [Badge.name]: Badge
  },
  data() {
    return {
      userList: []
    }
  },
  created() {
    this.getUserList()
  },
  methods: {
    // 获取用户列表
    async getUserList() {
      const { data: res } = await this.$http.get('/api/users')
      if (res.status !== 0) {
        this.$message.error(res.message)
      } else {
        console.log(res.data)
        this.userList = res.data
        this.$message.success(res.message)
      }
    }
  }
}
</script>

<style lang="less" scope>
.item {
  margin-right: 40px;
}
</style>
